//
//  HomeMeTopView.m
//  TQY
//
//  Created by 甘世清 on 2024/12/4.
//

#import "HomeMeTopView.h"
#import "VipViewController.h"
#import "AuthenticationViewController.h"
#import "InfoSetUpViewController.h"
#import "ShouChangViewController.h"
#import "LishiViewController.h"
@implementation HomeMeTopView
- (void)SQ_UIViewForSelfView{
    [self addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(88);
        make.left.equalTo(self).offset(16);
        make.top.equalTo(self).offset(TopHeight+30);
    }];
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView).offset(16);
        make.left.equalTo(self.headerView.mas_right).offset(8);
    }];
    [self addSubview:self.realStatusBtn];
    [self.realStatusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(24);
        make.left.equalTo(self.headerView.mas_right).offset(8);
        make.top.equalTo(self.headerView).offset(50);
    }];
    [self addSubview:self.vipImage];
    [self.vipImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(20);
        make.centerY.equalTo(self.nameLabel);
        make.left.equalTo(self.nameLabel.mas_right).offset(2);
    }];
   
    [self addSubview:self.vipButton];
    [self.vipButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.nameLabel);
            make.width.mas_equalTo(120);
            make.right.equalTo(self.mas_right);
            make.height.mas_equalTo(60);
    }];
    [self addSubview:self.zhuyeBtn];
    [self.zhuyeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(12);
            make.bottom.equalTo(self.mas_bottom).offset(-12);
        make.width.mas_equalTo(SCREEN_WIDETH/2.f-18);
        make.height.mas_equalTo(136);
    }];
    [self addSubview:self.shoucangBtn];
    [self.shoucangBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-12);
            make.top.equalTo(self.zhuyeBtn);
        make.width.mas_equalTo(SCREEN_WIDETH/2.f-18);
        make.height.mas_equalTo(62);
    }];
    [self addSubview:self.lishiBtn];
    [self.lishiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-12);
        make.bottom.equalTo(self.zhuyeBtn.mas_bottom);
        make.width.mas_equalTo(SCREEN_WIDETH/2.f-18);
        make.height.mas_equalTo(62);
    }];
    
    WS(weakSelf);
    [self.zhuyeBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_headerViewButtonClick];
    }];
    
    [self.shoucangBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        ShouChangViewController * vc = [[ShouChangViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }];
    [self.lishiBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        LishiViewController * vc = [[LishiViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }];
    [self.vipButton setTouchBlock:^(SQCustomButton * _Nonnull button) {
        VipViewController * vc = [[VipViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }];
    [self.realStatusBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        if ([UserModel share].realStatus == -1 ||[UserModel share].realStatus == 1) {
            AuthenticationViewController * vc = [[AuthenticationViewController alloc]init];
            [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
        } else  if ([UserModel share].realStatus == 0){
            [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"已提交认证,请等待审核结果")];
        }else{
            [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"认证已完成")];
        }
    }];
}

-(void)SQ_UIView{
    [self.headerView.headerImage sd_setImageWithURL:SQURLImage([UserModel share].portrait) placeholderImage:SQGetImage(@"1")];
    self.nameLabel.text = [UserModel share].name;
    if ([UserModel share].isVip) {
        self.vipButton.text = SQNSLocalString(@"已开通会员");
        self.vipButton.textColor = SQColor333333;
        self.vipImage.hidden = NO;
    } else {
        self.vipButton.text = SQNSLocalString(@"未开通会员");
        self.vipButton.textColor = SQColor999999;
        self.vipImage.hidden = YES;
    }
    if ([UserModel share].realStatus == 2) {
        self.realStatusBtn.image = SQGetImage(@"renzheng");
        self.realStatusBtn.text = SQNSLocalString(@"认证成功");
    } else {
        self.realStatusBtn.image = SQGetImage(@"unrenzheng");
        if ([UserModel share].realStatus == 0) {
            self.realStatusBtn.text = SQNSLocalString(@"审核中");
        } else   if ([UserModel share].realStatus == 1){
            self.realStatusBtn.text = SQNSLocalString(@"认证失败");
        }
    }
}
-(void)SQ_headerViewButtonClick{
    InfoSetUpViewController * vc = [[InfoSetUpViewController alloc]init];
    vc.isEdit = YES;
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(24);
        _nameLabel.textColor = UIColor.blackColor;
        _nameLabel.backgroundColor = UIColor.clearColor;
        _nameLabel.numberOfLines = 0;
      
    }
    return _nameLabel;
}

- (HeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HeaderView alloc]init];
        _headerView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
        _headerView.clipsToBounds = YES;
        _headerView.layer.cornerRadius = 44;
        _headerView.layer.masksToBounds = YES;
        [_headerView.btn addTarget:self action:@selector(SQ_headerViewButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _headerView;
}
 
- (SQCustomButton *)vipButton{
    if (!_vipButton) {
        _vipButton = [[SQCustomButton alloc]initType:SQCustomButtonRightImageType imageSize:CGSizeMake(16, 16) midmargin:4];
        _vipButton.backgroundColor = UIColor.clearColor;
        _vipButton.font = FONT_REGULAR(16);
        _vipButton.image = SQGetImage(@"返回");
        _vipButton.text = SQNSLocalString(@"未开通会员");
        _vipButton.textColor = SQColor666666;
    }
    return _vipButton;
}
- (UIImageView *)vipImage{
    if (!_vipImage) {
        _vipImage = [[UIImageView alloc]init];
        _vipImage.image = SQGetImage(@"huiyuanquanyi");
    }
    return _vipImage;
}

- (SQCustomButton *)realStatusBtn{
    if (!_realStatusBtn) {
        _realStatusBtn = [[SQCustomButton alloc]initType:SQCustomButtonRightImageType imageSize:CGSizeMake(16, 16) midmargin:2];
        _realStatusBtn.image = SQGetImage(@"unrenzheng");
        _realStatusBtn.text = SQNSLocalString(@"点击认证");
        _realStatusBtn.textColor = SQColor666666;
        _realStatusBtn.font = FONT_REGULAR(12);
    }
    return _realStatusBtn;
}
- (SQCustomButton *)zhuyeBtn{
    if (!_zhuyeBtn) {
        _zhuyeBtn = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(20, 20) midmargin:12];
        _zhuyeBtn.text = SQNSLocalString(@"主页");
        _zhuyeBtn.font = FONT_REGULAR(16);
        _zhuyeBtn.textColor = SQColor333333;
        _zhuyeBtn.image = SQGetImage(@"主页");
        _zhuyeBtn.SQBackimageView.image = SQGetImage(@"编组 9");
    }
    return _zhuyeBtn;
}
- (SQCustomButton *)shoucangBtn{
    if (!_shoucangBtn) {
        _shoucangBtn = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(20, 20) midmargin:12];
        _shoucangBtn.text = SQNSLocalString(@"收藏");
        _shoucangBtn.font = FONT_REGULAR(16);
        _shoucangBtn.textColor = SQColor333333;
        _shoucangBtn.image = SQGetImage(@"收藏");
        _shoucangBtn.SQBackimageView.image = SQGetImage(@"编组 11");
    }
    return _shoucangBtn;
}

- (SQCustomButton *)lishiBtn{
    if (!_lishiBtn) {
        _lishiBtn = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(20, 20) midmargin:12];
        _lishiBtn.text = SQNSLocalString(@"历史");
        _lishiBtn.font = FONT_REGULAR(16);
        _lishiBtn.textColor = SQColor333333;
        _lishiBtn.image = SQGetImage(@"历史");
        _lishiBtn.SQBackimageView.image = SQGetImage(@"编组 11");
    }
    return _lishiBtn;
}
@end
